﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Health : MonoBehaviour
{
    public float TotalBlood=100;
    private float Blood;
    public GameObject healthBar;
    public GameObject[] badGameO;
    private void Start()
    {
        Blood = TotalBlood;
        UpdateHealthBar();
    }
    public void DesBlood(float num)
    {
        Blood -= num;
        UpdateHealthBar();
    }
    private void Update()
    {
        if (Blood <= 0)
            Destroy(gameObject);
    }
    /*private void OnCollisionEnter2D(Collision2D collision)
    {
        foreach (GameObject go in badGameO)
        {
            if (collision.gameObject.tag==go.tag)
            {

            }
        }
    }*/
    private void OnTriggerEnter2D(Collider2D other)
    {
        foreach (GameObject badgame in badGameO)
        {
            if (badgame.tag == other.tag)
            {
                DesBlood(10);
                print(1);
            }
        }
    }

    void UpdateHealthBar()
    {
        healthBar.transform.localScale = new Vector3(0.15f*Blood/TotalBlood,0.15f,1);
    }
}
